<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>创建报价单</title>
<%@ include file="/WEB-INF/views/include/head.jsp"%>
<script src="${ctxStatic}/js/jquery-1.9.1.min.js"></script>
<script src="${ctxStatic}/js/DateTimePicker.js"></script>
<script src="${ctxStatic}/js/layer.js"></script>
<script src="${ctxStatic}/js/style.js"></script>
<link rel="stylesheet" href="${ctxStatic}/css/common.css">
<link rel="stylesheet" href="${ctxStatic}/css/layerSm.css">
<c:set value="<%=ResourcesUtil.getConfig(\"finance_category\") %>" var="fCategoryList"/>
<c:set value="<%=ResourcesUtil.getConfig(\"financeCategory01\") %>" var="financeCategory01"/>
<c:set value="<%=ResourcesUtil.getConfig(\"financeCategory02\") %>" var="financeCategory02"/>
<c:set value="<%=ResourcesUtil.getConfig(\"financeCategory03\") %>" var="financeCategory03"/>
<c:set value="<%=ResourcesUtil.getConfig(\"financeCategory04\") %>" var="financeCategory04"/>
<c:set value="<%=ResourcesUtil.getConfig(\"financeCategory05\") %>" var="financeCategory05"/>
<c:set value="<%=ResourcesUtil.getConfig(\"financeCategory06\") %>" var="financeCategory06"/>
<c:set value="<%=ResourcesUtil.getConfig(\"financeCategory07\") %>" var="financeCategory07"/>
<script>
    $(function(){
            $(".tabBox ul li").each(function(){
                var index=$(this).index();

                $(".tabBox ul li").eq(0).addClass("active");

                $(this).click(function(){

                    //alert(index);

                    $(this).addClass("active").siblings().removeClass("active");

                    $(".tabBoxSm > .tabSm").eq(index).stop(true).show().siblings().stop(true).hide();
					
					var tableW = $(".tabBoxSm > .tabSm").eq(index).find('.tableHead').width();
					var tabodyH = $(".tabBoxSm > .tabSm").eq(index).find('.tableBody').height();
					var tableScrollH = $(".tabBoxSm > .tabSm").eq(index).find('.tableScroll').height();
					if(tabodyH>tableScrollH){
						$(".tabBoxSm > .tabSm").eq(index).find('.tableScroll').css('width',tableW + 18 + 'px')
					}else{
						$(".tabBoxSm > .tabSm").eq(index).find('.tableScroll').css('width','inherit')
					}

                })

            })

        })
        
        $(document).ready(function(){
        $("select").select2();
        if ($("#financeId").val() != "") {
			$("select").attr("disabled",true);
			$("input").attr("disabled",true);
			$("textarea").attr("disabled",true);
			$("#showHtml").addClass("showHtml");
			$("#okButton").hide();
			if ($("#financeCategory").val() == 'FINANCE_CATEGORY-BUSINESS_07') {
				$("#auditButton").show();
			}
		}
		var form = $("#inputForm");  
        form.validate();//验证指定的表单
    	$("#okButton").click(function(){
    		if (form.valid()) {//如果表单验证成功，则进行提交。
    			if ($("#debitAmount").val() == "" && $("#creditAmount").val() == "") {
					tipParent("应付金额和应收金额请选填一项");
					return;
				}else if($("#debitAmount").val() != "" && $("#creditAmount").val() != ""){
    				tipParent("应付金额和应收金额只能填写其中一项");
    				return;
				}
    			$("select").attr("disabled",true);
	    		$("input").attr("disabled",true);
				$("textarea").attr("disabled",true);
	    		$("#showHtml").addClass("showHtml");
	    		$("#okHead").show();
	    		$("#createHead").hide(); 
	            return false;
	          
          	}
     	});
    });
    
    /* 保存创建/编辑信息 */
    function saveForm(){
    	$("#activity_pane").showLoading();
    	$("select,input,textarea").removeAttr("disabled");
    	unFormat($("#debitAmount"));
    	unFormat($("#creditAmount"));
    	var params = $("#inputForm").serialize();
    	$.post("${ctx}/settlement/single/save",params,function(result){
    		/* 弹出提示框,刷新父页面,关闭当前页面 */
    		tipParent(result);
    		 window.parent.frames[0].searchListForm();
    		closeWin();
    		$("#activity_pane").hideLoading();
    	},'json');
    	
    }
    /* 导出发票  */
    function exportInvoice() {
		window.location.href = "${ctx}/settlement/single/exportInvoice?financeId="+$("#financeId").val()+"&financeContractNo=${financeEntity.financeContractNo}";
	}
</script>
</head>
<body>
<form id="inputForm">
<!-- 创建编辑头部 -->   
<div id="createHead" class="layerHeader clearfix">
<c:choose>
	   <c:when test="${financeEntity.financeId!=null && financeEntity.financeId!=''}">
	    <!-- 编辑 --> 
			<p class="headerTitle">查看业务结算</p>
       </c:when>
       <c:otherwise>
        <!-- 创建 --> 
            <p class="headerTitle">创建业务结算</p>
       </c:otherwise>
    </c:choose>
	
    <div class="headerButton clearfix">
	    <c:if test="${financeEntity.financeCategory eq financeCategory04 || financeEntity.financeCategory eq financeCategory05 || financeEntity.financeCategory eq financeCategory06 }">
	    	<button type="button" onclick="exportInvoice();">导出发票</button>
	    </c:if>
    	<button type="button" id="auditButton" style="display: none;" onclick="popup('800px','519px','${ctx}/settlement/single/audit?id=${financeEntity.financeId }')">审核</button>
        <button type="button" id="okButton"><spring:message code="purchaseContract_edit_ok"/></button>
        <button type="button" onclick="closeWin()"><spring:message code="purchaseContract_edit_cancle"/></button>
    </div>
</div>
<!-- 确认页面head部 -->
		<div id="okHead" class="layerHeader clearfix" style="display:none">
			<p class="headerTitle"><spring:message code="settlement_confirm"/></p>
		    <div class="headerButton clearfix">
 		    	<shiro:hasPermission name="bookingspace:single:edit">
		        <button type="button" onclick="saveForm();"><spring:message code="common_save"/></button>
 				</shiro:hasPermission>
		        <button type="button" onclick="closeWin()"><spring:message code="btn_cancle"/></button>
		    </div>
		</div>

<div id="showHtml" class="tabBoxSm">
<input type="hidden" id="financeId" name="financeId" value="${financeEntity.financeId }">
<div class="smOrderBox" id="activity_pane">                          
        <div class="clearfix">               	
            	<div class="items clearfix">        	
                    <div class="col-50 clearfix">
                    <!-- 业务号 -->
                        <p class="tit">业务号</p>
                        <label id="financeNoLabel">${financeEntity.financeContractNo}</label>
                        <input type="hidden" id="financeContractNo" name="financeContractNo" value="${financeEntity.financeContractNo}"/>
                    </div>
                    <div class="col-50 clearfix haveToBox">
	                    <!-- 业务期间  -->
	                    <p class="tit">业务期间</p> 
	                    <c:choose>
						   <c:when test="${financeEntity.financeId!=null && financeEntity.financeId!=''}">
								<label><fmt:formatDate value="${financeEntity.financePeriod }" pattern="yyyy-MM"/></label>
					       </c:when>
					       <c:otherwise>
					            <label>${fns:getDate("yyyy-MM") }</label>
					       </c:otherwise>
					    </c:choose>
                        <input type="hidden" id="financePeriod" name="financePeriod" value="${fns:getDate('yyyy-MM') }"/>              
                    </div>
                </div>
                <div class="items clearfix">        	
                    <div class="col-50 clearfix">
                    <!-- 业务类别 -->
                        <p class="tit">业务类别</p>
                        <select id="financeCategory" name="financeCategory" style="width: 150px;" disabled="disabled">
	                    <option value="">请选择</option>
	                    <c:forEach items="${fns:getDictList(fCategoryList) }" var="fCategory">
	                    	<option value="${fCategory.itemCode }-${fCategory.itemValue }"
	                    	<c:choose>
							   <c:when test="${financeEntity.financeId!=null && financeEntity.financeId!=''}">
									<c:if test="${fn:split(financeEntity.financeCategory,'-')[1] eq fCategory.itemValue }">selected="selected"</c:if>
						       </c:when>
						       <c:otherwise>
						            <c:if test="${fn:split(financeCategory07,'-')[1] eq fCategory.itemValue }">selected="selected"</c:if>
						       </c:otherwise>
						    </c:choose>>${fCategory.itemName }</option>
	                    </c:forEach>
                    </select>
                    </div>
                </div> 
                <div class="items clearfix">        	
                    <div class="col-50 clearfix haveToBox">
                    <p class="tit">客户</p>
                        <select id="ognizationId" name="ognizationId" style="width: 150px;" data-rule-required="true" data-msg-required="请选择客户">
	                    <option value="">请选择</option>
	                    <c:forEach items="${ognizationList }" var="ognization">
	                    	<option value="${ognization.id }"
	                    	<c:if test="${financeEntity.ognizationId eq ognization.id }">selected="selected"</c:if>
	                    	>${ognization.ognizationName }</option>
	                    </c:forEach>
	                    </select>
                        <p class="haveTo">*</p>
                    </div>
                    <div class="col-50 clearfix haveToBox">
                    <!-- 货币类别 -->
                        <p class="tit">货币类别</p>
                        <c:set value="<%=ResourcesUtil.getConfig(\"quotationCurrency\") %>" var="qCurrencyList"/>
                        <select id="financeCurrency" name="financeCurrency" style="width: 150px;" data-rule-required="true" data-msg-required="请选择货币类别">
	                    <option value="">请选择</option>
	                    <c:forEach items="${fns:getDictList(qCurrencyList) }" var="qCurrency">
	                    	<option value="${qCurrency.itemCode }-${qCurrency.itemValue }"
	                    	<c:if test="${fn:split(financeEntity.financeCurrency,'-')[1] eq qCurrency.itemValue }">selected="selected"</c:if>
	                    	>${qCurrency.itemName }</option>
	                    </c:forEach>
	                    </select>
                        <p class="haveTo">*</p>
                    </div>
                </div>
                <div class="items clearfix">        	
                    <div class="col-50 clearfix">
                    <!-- 应付金额 -->
                        <p class="tit">应付金额</p>
                        <input type="text" id="debitAmount" name="debitAmount"  value="<fmt:formatNumber value="${financeEntity.debitAmount }" pattern="#,##0.00"/>" onfocus="unFormat(this)" onblur="formatMoney(this, 2)"/>
                    </div>
                    <div class="col-50 clearfix">
                    <!-- 应收金额 -->
                        <p class="tit">应收金额</p>
                        <input type="tel" id="creditAmount" name="creditAmount"  value="<fmt:formatNumber value="${financeEntity.creditAmount }" pattern="#,##0.00"/>" onfocus="unFormat(this)" onblur="formatMoney(this, 2)"/>
                    </div>
                </div>
                <div class="items clearfix"> 
                	<div class=" clearfix haveToBox">
                    <!-- 备注 -->
                        <p class="tit">备注</p>
                        <textarea id="remarks" name="remarks" style="width: 450px;height: 170px;">${financeEntity.remarks }</textarea>
                    </div>
                </div>
               </div>
            </div>
       </div>                 
		    	
</form>
<script>
	window.onload = function(){
			var windowH = window.innerHeight
					||document.documentElement.clientHeight
					||document.body.clientHeight
			$('.tabSm').css({
				'height':windowH - 77,
			});
			$('.tableScrollSm').css({
				'height':windowH - 91
			})
		}
	$('.squareL').on('click', function() {
	    var lastCon = $('.square ol li:last-child').detach();
	    $('.square ol').prepend(lastCon)
	    $('.square ol li:last-child').addClass('active')
	    $('.square ol li:last-child').siblings().removeClass('active')
	})

	$('.squareR').on('click', function() {
	    var lastCon = $('.square ol li:first-child').detach();
	    $('.square ol').append(lastCon)
	    $('.square ol li:last-child').addClass('active')
	    $('.square ol li:last-child').siblings().removeClass('active')
	})
</script>
</body>
</html>
